<template>
  <div class="goods-item" @click="itemClick">
    <!-- v-lazy="showImage" 当v-lazy中的showImage未加载时 则显示默认图片 -->
    <img :key="showImage" alt="" @load="imageLoad" v-lazy="showImage" />
    <div class="goods-info">
      <p>{{ goodsItem.title }}</p>
      <span class="price">{{ "¥ " + goodsItem.price }}</span>
      <span class="collect">{{ goodsItem.cfav }}</span>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    goodsItem: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  methods: {
    imageLoad() {
      // 用$bus总线传出监听事件 由home接收
      this.$bus.$emit("itemImageLoad");
    },

    itemClick() {
      // this.$router.push('/detail/:iid')
      // push 跳转 有返回
      // replace 跳转 无返回
      this.$router.push("/detail/" + this.goodsItem.iid);
    },
  },
  computed: {
    showImage() {
      return (
        this.goodsItem.img || this.goodsItem.image || this.goodsItem.show.img
      );
    },
  },
};
</script>

<style scoped>
.goods-item {
  padding-bottom: 40px;
  position: relative;
  width: 48%;
  margin-bottom: 20px;
  border-radius: 8px;
  border: 3px solid seashell;
  box-shadow: 4px 6px 10px #95a5a6;
  background: url("../../../assets/img/regisetr/login2.jpg");
}

.goods-item img {
  width: 100%;
  border-radius: 8px;
  box-shadow: 4px 6px 10px #95a5a6;
  /* border:3px solid var(--color-tint); */
  margin-bottom: 3px;
}

.goods-info {
  font-size: 12px;
  position: absolute;
  bottom: 5px;
  left: 0;
  right: 0;
  overflow: hidden;
  text-align: center;

  font-weight: bold;
}

.goods-info p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 3px;
  color: #000;
}

.goods-info .price {
  color: var(--color-high-text);
  margin-right: 30px;
  font-size: 18px;
}

.goods-info .collect {
  position: relative;
}

.goods-info .collect::before {
  content: "";
  position: absolute;
  left: -15px;
  top: -1px;
  width: 14px;
  height: 14px;
  background: url("~assets/img/common/collect.svg") 0 0/14px 14px;
}
</style>
